﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Elkitools.EditorParts.ListSelector.Tools;

namespace Elkitools.EditorParts.ListSelector.Controls
{
    /// <summary>
    /// The goal of this class is to make a map of all calendar lists in the current SPSite
    /// </summary>
    [Serializable]
    internal class CalendarModel
    {
        //-------------------------------------------------------------------------
        #region Properties
        //-------------------------------------------------------------------------

        /// <summary>
        /// Root Web of the current SPSite
        /// </summary>
        internal CalendarWebData RootWebData { get; set; }

        //-------------------------------------------------------------------------
        #endregion Properties
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        #region Constructor & initializations
        //-------------------------------------------------------------------------

        /// <summary>
        /// Default constructor
        /// </summary>
        internal CalendarModel()
        {
        }

        /// <summary>
        /// Constructor taking the reference SPSite as parameter
        /// </summary>
        /// <param name="pobjSite"></param>
        internal CalendarModel(SPSite pobjSite)
        {
            InitializeData(pobjSite);
        }

        /// <summary>
        /// Internal data initialization
        /// </summary>
        /// <param name="pobjSite"></param>
        private void InitializeData(SPSite pobjSite)
        {
            try
            {
                if (pobjSite.RootWeb != null)
                {
                    RootWebData = new CalendarWebData(pobjSite.RootWeb);
                }
            }
            catch(Exception excGetWebs)
            {
                UlsLogger.Error("An error occurred while Initializing SPSite webs and lists in CalsndarListsInSPSite : " + excGetWebs.Message);
            }
        }

        //-------------------------------------------------------------------------
        #endregion Constructor & initializations
        //-------------------------------------------------------------------------
    }
}
